<?php
/*------------------------------------------------------------------------------
this file is part of Web Application Kit http://webappkit.net
Copyright (C) 2006 J.Ducastel <fredbird@fredbird.org>

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
------------------------------------------------------------------------------*/

/**
* handler for "script" events type
* @author J.Ducastel <fredbird@fredbird.org>
* @version 
*/
class wakEvents_script extends wakService {
/*------------------------------------------------------------------------------
                                                                     constructor
------------------------------------------------------------------------------*/
	/**
	*
	* @access
	* /
	function wakEventHandler_script() {
		$this->__construct();
	}/**/
	
	/**
	*
	* @access
	* /
	function __construct() {
		parent::__construct();
	}/**/
/*------------------------------------------------------------------------------
                                                                  public methods
------------------------------------------------------------------------------*/
	/**
	* executes event and returns event's return vaalue
	* @param wakEvents_eventCall $call
	* @param wakParameters $parameters
	* @access public
	* @return mixed event result
	*/
	function & run($call,$parameters) {
		$r=null;
		//$deb=&wak::getservice('wakdebug');
		//echo "running ".wakdebug::vardump($event);
		$file=$this->_searchEventFile($call);
		// 
		// setting parameters global reference
		global $PARAMETERS;
		$PARAMETERS=&$parameters;
		// including script
		if (file_exists($file)) {
			$r=include($file);
		} else if (file_exists('/'.$file)) {
			// dirty hack for web hosts using only absolute paths
			$r=include('/'.$file);
		} else {
			throw new Exception('could not find event file for '.$call);
			//wakapi::warning('could not find event file for '.$eventCall);
		}
		return $r;
	}/**/

	/**
	* 
	* @param
	* @access public
	* @return 
	* /
	function () {
		
	}/**/
	
	/**
	* 
	* @param
	* @access public
	* @return 
	* /
	function () {
		
	}/**/
/*------------------------------------------------------------------------------
                                                                      properties
------------------------------------------------------------------------------*/
	/**
	* @var type desc
	*/
	//var //
	protected $cfg=array(
		'path'=>'app/wakevents/script/'
	);
/*------------------------------------------------------------------------------
                                                                 private methods
------------------------------------------------------------------------------*/
	/**
	* searches for event file
	* @param
	* @access private
	* @return 
	*/
	protected function _searchEventFile($call) {
		$seg=$call->get('segments');
		$base=$seg[1];
		$file=$this->cfg['path'].$base.'.wakevent.php';
		if (!file_exists($file)) {
			// echo $file;
			return false;
		}
		return $file;
	}/**/
	
	/**
	* 
	* @param
	* @access private
	* @return 
	* /
	function () {
		
	}/**/
}
?>
